#include <iostream>
using namespace std;

//冒泡排序
void sort1(int a[],int len)
{
    int i,j,t;
    for(i=0;i<len-1;i++)
        for(j=0;j<len-i;j++){
            if(a[j]<a[j+1])
            {
                t=a[j];
                a[j]=a[j+1];
                a[j+1]=t;
            }
        }
    cout<<"冒泡排序的结果:"<<endl;
    for(i=0;i<len;i++)
        cout<<a[i]<<" ";
    cout<<endl;
}
//选择排序
void sort2(int a[],int len)
{
    int i,j,max,t;
    for(i=0;i<len-1;i++){
        max = i;
        for(j=i+1;j<len;j++){
            if(a[j]>a[max])
                max = j;
        }
        if(max!=i){
            t=a[i];
            a[i]=a[max];
            a[max]=t;
        }
    }
    cout<<"选择排序的结果:"<<endl;
    for(i=0;i<len;i++)
        cout<<a[i]<<" ";
    cout<<endl;
}
//插入排序
void sort3(int a[],int len)
{
    int i ,j,t;
    for (i=1;i<len;i++){
        t = a[i];
        for(j=i-1;j>=0&&a[j]<t;j--){
            a[j+1]=a[j];
        }
        a[j+1]=t;
    }
    cout<<"插入排序的结果:"<<endl;
    for(i=0;i<len;i++)
        cout<<a[i]<<" ";
    cout<<endl;
}

int main()
{
    int len;
    cout<<"输入数组长度:";
    cin>>len;
    int *a;
    a = new int[len];
    for(int i=0;i<len;i++)
    {
        a[i] = rand()%50;
    }
    sort1(a,len);
    sort2(a,len);
    sort3(a,len);
    return 0;
}